package com.xyzh05.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;


@Entity
@Table(name="transaction")
@Searchable
@XmlRootElement
public class Transaction extends BaseObject implements Serializable {
	private static final long serialVersionUID = -7964383298040613389L;
	
	public static final int NEW = -1;
	public static final int CANCEL = -2;
	public static final int PAY = 0;
	public static final int START = 1;
	public static final String PAYMENT_OVERTIME = "paymentOvertime";
	public static final String CANCEL_BY_USER = "cancelByUser";
	public static final String CANCEL_BY_ADMIN = "cancelByAdmin";
	
	private Long id;
    private Long status;
//    private Long editorId;
//    private Long serviceId;
    private User user;
    private Date startTime;
    private Date deadline;
    private Date finishtime;
    private Double payment;
    private Integer payType;
    private Boolean clientupdated;
    private Boolean editorupdated;
    private Boolean payed;
    private Long schoolNum;
    private String showId;
    private String remark;
    private List<TransactionEntry> entries;
   

	@OneToMany( mappedBy = "transaction", fetch = FetchType.LAZY) 
    public List<TransactionEntry> getEntries() {
		return entries;
	}

	public void setEntries(List<TransactionEntry> entries) {
		this.entries = entries;
	}

	@Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="status", nullable=false)
    @SearchableProperty
    public Long getStatus() {
        return this.status;
    }
    
    public void setStatus(Long status) {
        this.status = status;
    }
    
//    @Column(name="editorid", nullable=false)
//    @SearchableProperty
//    public Long getEditorId() {
//        return this.editorId;
//    }
//    
//    public void setEditorId(Long editorId) {
//        this.editorId = editorId;
//    }
    
//    @Column(name="serviceid", nullable=false)
//    @SearchableProperty
//    public Long getServiceId() {
//        return this.serviceId;
//    }
//    
//    public void setServiceId(Long serviceId) {
//        this.serviceId = serviceId;
//    }
    
    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="clientid", nullable=false)
    public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="starttime", nullable=false, length=19)
    @SearchableProperty
    public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="deadline", nullable=false, length=19)
    @SearchableProperty
    public Date getDeadline() {
        return this.deadline;
    }


	public void setDeadline(Date deadline) {
        this.deadline = deadline;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="finishtime", nullable=false, length=19)
    @SearchableProperty
    public Date getFinishtime() {
        return this.finishtime;
    }
    
    public void setFinishtime(Date finishtime) {
        this.finishtime = finishtime;
    }
    
    @Column(name="payment", nullable=false, precision=22, scale=0)
    @SearchableProperty
    public Double getPayment() {
        return this.payment;
    }
    
    public void setPayment(Double payment) {
        this.payment = payment;
    }
    
    @Column(name="paytype", nullable=false)
    @SearchableProperty
    public Integer getPayType() {
		return payType;
	}

	public void setPayType(Integer payType) {
		this.payType = payType;
	}
    
    @Column(name="clientupdated")
    @SearchableProperty
    public Boolean getClientupdated() {
        return this.clientupdated;
    }


	public void setClientupdated(Boolean clientupdated) {
        this.clientupdated = clientupdated;
    }
    
    @Column(name="editorupdated")
    @SearchableProperty
    public Boolean getEditorupdated() {
        return this.editorupdated;
    }
    
    public void setEditorupdated(Boolean editorupdated) {
        this.editorupdated = editorupdated;
    }
    
    @Column(name="payed", nullable=false)
    @SearchableProperty
    public Boolean getPayed() {
        return this.payed;
    }
    
    public void setPayed(Boolean payed) {
        this.payed = payed;
    }
    
    @Column(name="schoolNum")
    @SearchableProperty
    public Long getSchoolNum() {
        return this.schoolNum;
    }
    
    public void setSchoolNum(Long schoolNum) {
        this.schoolNum = schoolNum;
    }
    
    @Column(name="showid", length=20)
    @SearchableProperty
    public String getShowId() {
        return this.showId;
    }
    
    public void setShowId(String showId) {
        this.showId = showId;
    }
    
    @Column(name="remark", length=20)
    @SearchableProperty
    public String getRemark() {
        return this.remark;
    }
    
    public void setRemark(String remark) {
        this.remark = remark;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Transaction pojo = (Transaction) o;

        if (status != null ? !status.equals(pojo.status) : pojo.status != null) return false;
//        if (editorId != null ? !editorId.equals(pojo.editorId) : pojo.editorId != null) return false;
//        if (serviceId != null ? !serviceId.equals(pojo.serviceId) : pojo.serviceId != null) return false;
        if (user != null ? !user.equals(pojo.user) : pojo.user != null) return false;
        if (startTime != null ? !startTime.equals(pojo.startTime) : pojo.startTime != null) return false;
        if (deadline != null ? !deadline.equals(pojo.deadline) : pojo.deadline != null) return false;
        if (finishtime != null ? !finishtime.equals(pojo.finishtime) : pojo.finishtime != null) return false;
        if (payment != null ? !payment.equals(pojo.payment) : pojo.payment != null) return false;
        if (payType != null ? !payType.equals(pojo.payType) : pojo.payType != null) return false;
        if (clientupdated != null ? !clientupdated.equals(pojo.clientupdated) : pojo.clientupdated != null) return false;
        if (editorupdated != null ? !editorupdated.equals(pojo.editorupdated) : pojo.editorupdated != null) return false;
        if (payed != null ? !payed.equals(pojo.payed) : pojo.payed != null) return false;
        if (schoolNum != null ? !schoolNum.equals(pojo.schoolNum) : pojo.schoolNum != null) return false;
        if (showId != null ? !showId.equals(pojo.showId) : pojo.showId != null) return false;
        if (remark != null ? !remark.equals(pojo.remark) : pojo.remark != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (status != null ? status.hashCode() : 0);
//        result = 31 * result + (editorId != null ? editorId.hashCode() : 0);
//        result = 31 * result + (startTime != null ? serviceId.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        result = 31 * result + (startTime != null ? startTime.hashCode() : 0);
        result = 31 * result + (deadline != null ? deadline.hashCode() : 0);
        result = 31 * result + (finishtime != null ? finishtime.hashCode() : 0);
        result = 31 * result + (payment != null ? payment.hashCode() : 0);
        result = 31 * result + (payType != null ? payType.hashCode() : 0);
        result = 31 * result + (clientupdated != null ? clientupdated.hashCode() : 0);
        result = 31 * result + (editorupdated != null ? editorupdated.hashCode() : 0);
        result = 31 * result + (payed != null ? payed.hashCode() : 0);
        result = 31 * result + (schoolNum != null ? schoolNum.hashCode() : 0);
        result = 31 * result + (showId != null ? showId.hashCode() : 0);
        result = 31 * result + (remark != null ? remark.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("status").append("='").append(getStatus()).append("', ");
//        sb.append("editorId").append("='").append(getEditorId()).append("', ");
//        sb.append("serviceId").append("='").append(getServiceId()).append("', ");
        sb.append("clientId").append("='").append(getUser()).append("', ");
        sb.append("starttime").append("='").append(getStartTime()).append("', ");
        sb.append("deadline").append("='").append(getDeadline()).append("', ");
        sb.append("finishtime").append("='").append(getFinishtime()).append("', ");
        sb.append("payment").append("='").append(getPayment()).append("', ");
        sb.append("payType").append("='").append(getPayType()).append("', ");
        sb.append("clientupdated").append("='").append(getClientupdated()).append("', ");
        sb.append("editorupdated").append("='").append(getEditorupdated()).append("', ");
        sb.append("payed").append("='").append(getPayed()).append("', ");
        sb.append("schoolNum").append("='").append(getSchoolNum()).append("', ");
        sb.append("showId").append("='").append(getShowId()).append("', ");
        sb.append("remark").append("='").append(getRemark()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
